<?php

namespace App\Http\Controllers\Service;

use App\Exceptions\GeneralException;
use App\Http\Controllers\Controller;
use App\Repositories\UserLogRepository;
use App\Repositories\ServiceBillRepository;
use App\Http\Requests\Admin\ServiceBill\QueryResource;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class ServiceBillController extends Controller
{
    protected $serviceBillRepository;
    protected $userLogRepository;

    /**
     * AdminController constructor.
     * @param ServiceBillRepository $serviceBillRepository
     * @param UserLogRepository $userLogRepository
     */
    public function __construct(
        ServiceBillRepository $serviceBillRepository,
        UserLogRepository $userLogRepository
    )
    {
        $this->serviceBillRepository = $serviceBillRepository;
        $this->userLogRepository = $userLogRepository;
    }

    /**
     * 获取站点账单
     *
     * Date: 2018/05/18
     * @author Tenny
     * @param QueryResource $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(QueryResource $request)
    {
        $limit = $request->get('paginate', 15);
        $name = $request->get('service_name', false);
        $created_at = $request->get('month', false);
        if ($name === null) {
            $name = false;
        }
        if ($created_at === null) {
            $created_at = false;
        }
        $admins = $this->serviceBillRepository->getStationBills($name, $created_at, $limit);
        return success($admins);
    }
}
